package com.manster.controller;

import com.manster.service.SysUserService;
import com.manster.util.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author manster
 * @Date 2022/3/13
 **/
@RestController
@Api(tags = "测试")
public class TestController {

    @Autowired
    SysUserService userService;

    @Autowired
    BCryptPasswordEncoder bCryptPasswordEncoder;

    @PreAuthorize("hasRole('admin')")
    @ApiOperation(value = "测试用户列表")
    @GetMapping("/test/pass")
    public R pass(){
        //加密后密码
        String password = bCryptPasswordEncoder.encode("123456");
        //匹配密码
        boolean matches = bCryptPasswordEncoder.matches("123456", password);

        System.out.println("密码匹配结果:" + matches);

        return R.success().data(password);
    }

    @ApiOperation(value = "测试用户列表")
    @GetMapping("/test")
    public R test(){
        return R.success().data(userService.list());
    }
}
